<%@ page import="java.util.List" %>
<%@ page import="cn.edu.hziee.Grade" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: ykd95
  Date: 2022/4/19
  Time: 9:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
  <head>
    <title>$Title$</title>
    <script src="jquery-3.6.0.js"></script>
    <script>
      $(function () {
        $('.add').click(function () {
            var Text=$(this).parent().parent().find("input:text");
            $.post("/Traversal/AddServlet",{
              Number:Text.eq(0).val(),
              Name:Text.eq(1).val(),
              Chinese:Text.eq(2).val(),
              Math:Text.eq(3).val(),
              English:Text.eq(4).val(),
            });
            window.location.reload();
            window.location.reload();
        })


      })
    </script>
  </head>
  <body>
    <%
      List<Grade> grades = null;
    %>
    <c:choose>
      <c:when test="${sessionScope==null}"/>
      <c:otherwise>
        <%
          grades = (List<Grade>) session.getAttribute("card");
        %>
      </c:otherwise>
    </c:choose>

    <c:url var="update"
         value="UpdateServlet?id="/>
    <c:url var="delete"
         value="DeleteServlet?id="/>

    <table border="1">
      <tr>
        <td>&nbsp;学号&nbsp;</td>
        <td>&nbsp;姓名&nbsp;</td>
        <td>&nbsp;语文&nbsp;</td>
        <td>&nbsp;数学&nbsp;</td>
        <td>&nbsp;英语&nbsp;</td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
      </tr>
      <c:forEach var="grade" items="<%=grades%>" >
        <tr>
          <td>${grade.number}</td>
          <td>${grade.name}</td>
          <td>${grade.chinese}</td>
          <td>${grade.math}</td>
          <td>${grade.english}</td>
          <td><a href="${update}${grade.id}">修改</a></td>
          <td><a href="${delete}${grade.id}">删除</a></td>
        </tr>
      </c:forEach>
      <tr>
        <td><input type="text" name="number"></td>
        <td><input type="text" name="name"></td>
        <td><input type="text" name="chinese"></td>
        <td><input type="text" name="math"></td>
        <td><input type="text" name="english"></td>
        <td><button class="add" onclick="">添加</button></td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
      </tr>
    </table>
  <form action="/Traversal/FindServlet" method="get">
     <input type="text" name="find">
    <input type="submit" value="查询">
  </form>
  </body>
</html>
